package ua.com.mind_tree.client;

import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.safecss.shared.SafeStyles;
import com.google.gwt.safecss.shared.SafeStylesUtils;
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.Widget;
import ua.com.mind_tree.client.experience.Experience;
import ua.com.mind_tree.client.experience.ExperienceType;

import java.util.Set;

/**
 * @author suamo ( 01.05.12 2:03 )
 */
public class ExpCell extends AbstractCell<Experience> {

    /**
     * The html of the image used for contacts.
     */
//    private final String imageHtml;
//
//    public ExCell(ImageResource image) {
//        this.imageHtml = AbstractImagePrototype.create(image).getHTML();
//    }

    @Override
    public void render(Context context, Experience value, SafeHtmlBuilder sb) {
        // Value can be null, so do a null check..
        if (value == null) {
            return;
        }

        sb.appendHtmlConstant("<table>");

        // Add the contact image.
//        sb.appendHtmlConstant("<tr><td rowspan='3'>");
//        sb.appendHtmlConstant(imageHtml);
//        sb.appendHtmlConstant("</td>");

        // Add the name and address.
        sb.appendHtmlConstant("<img class='"+ getExpIconStyleClass(value.getType()) +"' src='/img/" + value.getType().name().toLowerCase() + ".png'/><td class='exp-title'>");
        sb.appendEscaped(value.getName());
        sb.appendHtmlConstant("</td></tr><tr><td class='exp-creator'>");
        sb.appendEscaped(value.getCreator());
        sb.appendHtmlConstant("</td></tr></table>");
    }

    private String getExpIconStyleClass(ExperienceType type) {
        switch (type){
            case BOOK: return "book-icon";
            case MOVIE: return "movie-icon";
            default: return "";
        }
    }
}
